package com.wp.controller;

import com.wp.pojo.PageResult;
import com.wp.pojo.Tag;
import com.wp.pojo.basePojo.SysResult;
import com.wp.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/tag")
@CrossOrigin
public class TagController {
    @Autowired
    private TagService tagService;
    /**
     * 新增标签
     * */
    @PostMapping("/add")
    public SysResult addTag(@RequestBody Tag tag){
        tagService.addTag(tag);
        return SysResult.success();
    }
    /**
     * 编辑标签
     * */
    @PostMapping("/edit")
    public SysResult editTag(@RequestBody Tag tag) {
        tagService.editTag(tag);
        return SysResult.success();
    }
    /**
     * 删除标签
     * */
//    @PostMapping("/delete")
//    public SysResult deleteTag(@RequestBody Tag tag){
//        tagService.deleteTag(tag);
//        return SysResult.success();
    @PostMapping("/delete")
    public SysResult deleteTag(@RequestBody Tag tag){
        tagService.deleteTag(tag.getUid());
        return SysResult.success();
    }

    /**
     * 获取所有标签列表
     * */
    @GetMapping("/getList")
    public SysResult getList(PageResult pageResult){
        PageResult pageResults = tagService.getTagList(pageResult);
        return SysResult.success(pageResults);
    }
}
